package dao;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.classic.Session;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import to.Cargo;
import to.Situacao;
import util.HibernateUtil;

public class CargoDAO {

	public List<Cargo> criaListaCargo() {

		List<Cargo> listaCargo = new ArrayList<Cargo>();
		Session session = null;

		try {
			session = HibernateUtil.getSessionFactory().openSession();
			Criteria criteria = session.createCriteria(Cargo.class, "c");
			criteria.addOrder(Order.asc("c.descricao"));
			listaCargo = (List<Cargo>) criteria.list();

		} catch (Exception e) {
			e.printStackTrace();
		}
		return listaCargo;

	}

	public Cargo buscaCargoPorCodigo(Integer c) {

		Cargo cg = new Cargo();
		Session session = null;

		try {
			session = HibernateUtil.getSessionFactory().openSession();
			Criteria criteria = session.createCriteria(Cargo.class, "ca");
			criteria.add(Restrictions.eq("ca.id", c));
			cg = (Cargo) criteria.uniqueResult();

		} catch (Exception e) {
			e.printStackTrace();
		}

		return cg;
	}

}
